JavaScript provides different methods to display output, such as console.log()
,
alert()
, document.write()
, and manipulating HTML elements directly.
console.log()
The console.log()
method is used for logging messages to the console. It is a debugging tool
available in most web browsers.
console.log("Hello, World!");
alert()
The alert()
method displays an alert box with a specified message and an OK button.
alert("Hello, World!");
document.write()
The document.write()
method writes a string of text to a document stream opened by
document.open()
.
document.write("Hello, World!");
innerHTML
The innerHTML
property sets or returns the HTML content (inner HTML) of an element.
document.getElementById("demo").innerHTML = "Hello, World!";